//
//  HWReadRecordViewController.m
//  嗨文
//
//  Created by 响当当 on 2019/2/18.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWCashDrawViewController.h"
#import "HWCashDrawView.h"

@interface HWCashDrawViewController ()
@property (nonatomic, strong)HWCashDrawView *caseDrawView;
@property (nonatomic, strong)NSDictionary *dic;
@end

@implementation HWCashDrawViewController

- (HWCashDrawView *)caseDrawView
{
    if (!_caseDrawView)
    {
        _caseDrawView = [[HWCashDrawView alloc]initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT-NAVIBAR_HEIGHT)];
        WeakSelf(self)
        _caseDrawView.getBackInfoBlock = ^(NSString *haiLevelNum, NSString *page) {
            [weakSelf getHaiFriendInfo:[NSString stringWithFormat:@"%ld",haiLevelNum.integerValue+1] pageNum:page pageSizes:@"10"];
        };
        _caseDrawView.changeSegmentBlock = ^(NSString *segmentNum) {
            [weakSelf getHaiFriendInfo:[NSString stringWithFormat:@"%ld",segmentNum.integerValue+1] pageNum:@"1" pageSizes:@"10"];
        };
    }
    return _caseDrawView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self buryPoint];
    
    [self setTitle:@"余额提现"];
    [self setDefaultNav];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self getInfor];
    [self getHaiFriendInfo:@"1" pageNum:@"0" pageSizes:@"10"];

    [self.view addSubview:self.caseDrawView];
}


#pragma mark - 余额提现
- (void)getInfor
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token                               };
   self.dic = [[NSDictionary alloc]init];
    
    WeakSelf(self)
    [MyInfoManager setCashWithdrawal:prarmers sucess:^(id  _Nonnull acceptData) {
        [SVProgressHUD show];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        HWCashDrawModel *model = [[HWCashDrawModel alloc]initWithDic:acceptData];
          [weakSelf.caseDrawView getDate:model];
    } fail:^(NSError * _Nullable error) {
        DISMISS_SVP(1.0f);
        [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
        DISMISS_SVP(1.0f);
    }];
    
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_CASHWIDTHDRAWNUM) withPramater:prarmers sucess:^(id responseObject) {
        weakSelf.dic = responseObject[@"data"];
        [weakSelf.caseDrawView getDateSegmentNum:responseObject[@"data"]];
    } failure:^(NSError *error) {
    }];
}


#pragma mark -嗨friend
- (void)getHaiFriendInfo:(NSString *)haiLevel pageNum:(NSString *)pagenum pageSizes:(NSString *)pagesize
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"haiLevel" : haiLevel,
                               @"pageNum" : pagenum,
                               @"pageSize" : pagesize
                               };
    
    WeakSelf(self)
    [MyInfoManager setCashWithdrawalList:prarmers sucess:^(id  _Nonnull acceptData) {
        NSNumber *nub = IFNULL(acceptData[@"hasNextPage"], [NSNumber new]);
        NSArray *arr = [NSArray arrayWithArray:acceptData[@"list"]];
        [weakSelf.caseDrawView getCashDrawList:arr hasNextPage:nub];
    } fail:^(NSError * _Nullable error) {
        DISMISS_SVP(1.0f);
        [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
        DISMISS_SVP(1.0f);
    }];
}

- (void)buryPoint
{
    NSString *lastStayTime = [kUserDefaults objectForKey:@"time"];
    NSString *nowStayTime = [NSString stringWithFormat:@"%ld",[[HWUtilties getNowTimeTimestamp3] integerValue] - lastStayTime.integerValue];
    
    [HWUtilties buryPointWithStayTime:nowStayTime
                            timestamp:[HWUtilties getNowTimeTimestamp3]
                             memberId:current_User.userID
                              fromUrl:nil
                                toUrl:@"/accountBalance"
                               fromId:nil
                                 toId:@"4e38a28170d25002"];
}
@end
